<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
    
    <div style="margin-top:50px;"><h2 style="color:#009688;margin-left:520px;">修改密码</h2><hr class="layui-bg-green"></div>
     <div style="margin-left:380px;margin-top: 100px;">
        <form class="layui-form" action="/updatePassword" method="post">
           <div class="layui-form-item">
              <label class="layui-form-label">旧密码：</label>
              <div class="layui-input-inline">
                 <input type="text" id="oldPassword" name="oldPassword" lay-verify="required" class="layui-input" placeholder="请输入密码">
              </div>
           </div>
            <div class="layui-form-item">
               <label class="layui-form-label">新密码：</label>
               <div class="layui-input-inline">
                  <input type="password" id="newPassword" name="newPassword"  lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
               </div>
               <div class="layui-form-mid layui-word-aux"><span  th:text="${newMsg}"></span></div>
             </div>
              <div class="layui-form-item">
               <label class="layui-form-label">确认密码：</label>
               <div class="layui-input-inline">
                  <input type="password" id="rePassword" name="rePassword"  lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
               </div>
               <div class="layui-form-mid layui-word-aux"><span th:text="${reMsg}"></span></div>
             </div>
             <div class="layui-form-item">
               <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
               </div>
             </div>
        </form>
     </div>
     <script src="layui/layui.js"></script>
     <script type="text/javascript">
         //var oldPassword=$("#oldPassword").val;
 	     //var newPassword=$("#newPassword").val;
         //var rePassword=$("#rePassword").val;
         //alert(oldPAssword);
        layui.use(['jquery','form'],function(){
        	
        	var form=layui.form;
        	var $=layui.jquery;
        	
        	form.verify({
        		pass: [
        		      /^[\S]{6,12}$/
        		      ,'密码必须6到12位，且不能出现空格'
        		    ]
        	});
        	form.on('submit(formDemo)',function(data){
        	//	alert(JSON.stringify(data.field));
        		$.ajax({
        			url:'/updatePassword',
        			type:'post',
        			async:false,
        			data:data.field,
        		//	contentType:"application/json;charset=utf-8",
        			success:function(data){
        				if(data==-1){
        					layer.msg("修改成功");
        					window.setTimeout(function(){window.parent.location.href="login.html";},500)
        				  }else if(data==0){
        					  layer.msg("旧密码错误");
        					  window.setTimeout(function(){window.location.href="updatePassword.html";},500)
        				  }else if(data==1){
        					  layer.msg("新密码不能喝旧密码相同");
        					  window.setTimeout(function(){window.location.href="updatePassword.html";},500)
        				  }else if(data==2){
        					  layer.msg("两次密码不相同");
        					  window.setTimeout(function(){window.location.href="updatePassword.html";},500)
        				  }
        			},
        			error:function(){
        				     layer.msg("修改失败");
        					window.setTimeout(function(){window.location.href="updatePassword.html";},500)
        				}
        	//		}
        		});
        		return false;
        	});
        });
     </script>
</body>
</html>